package com.org.manhu.chargehelper.adapter;

import java.util.List;
import java.util.Map;

import com.org.manhu.chargehelper.R;
import com.org.manhu.chargehelper.constant.Constant;
import com.org.manhu.chargehelper.tools.DateUtil;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 *
 * @文件名：ExchangeAdapter.java
 * @包名：com.org.manhu.Adapter
 * @作者：李朋辉 @ QQ：892839211
 * @创建时间：2014年11月27日 下午6:01:20
 * @描述：
 */
public class LogListAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<Map<String, String>> mList;
	private String flag;

	public LogListAdapter(Context context, List<Map<String, String>> list,
			String flag) {
		inflater = LayoutInflater.from(context);
		mList = list;
		this.flag = flag;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.log_list_item, null);
			holder.timeTxt = (TextView) convertView
					.findViewById(R.id.list_time);
			holder.typeTxt = (TextView) convertView
					.findViewById(R.id.list_type);
			holder.numTxt = (TextView) convertView.findViewById(R.id.list_num);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Map<String, String> map = mList.get(position);
		holder.timeTxt.setText(DateUtil.formatDate(map.get("CreateTime")));
		if (flag.equals(Constant.LOG_LIST_AWARD_FLAG)) {
			holder.typeTxt.setText(map.get("action"));
			holder.numTxt.setText(map.get("Money") + "元");
		} else if (flag.equals(Constant.LOG_LIST_COST_FLAG)) {
			holder.typeTxt.setText(map.get("Remark"));
			holder.numTxt.setText(map.get("StateName"));
		}
		

		return convertView;
	}

	public void setData(List<Map<String, String>> data) {
		mList.addAll(data);
	}

	public void clearData() {
		mList.clear();
	}

	class ViewHolder {
		TextView timeTxt, typeTxt, numTxt;
	}

}
